home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / setRigidKeyframe.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.6 KB  |  142 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  ==================== setRigidKeyframe.mel ==========
  22. //
  23. //  SYNOPSIS
  24. //      Create keyframes for the active/passive attribute
  25. //      of rigid bodies.
  26. //
  27. global proc setRigidKeyframe( int $type )
  28. //
  29. //  Description:
  30. //
  31. //    This proc creates keyframes for the active/passive attribute
  32. //    of rigid bodies.  
  33. //
  34. {
  35.     string $selObj[] = `ls -sl`;
  36.     string $parentName;
  37.     int    $isRigid = 0; 
  38.     int    $currentType;
  39.     float  $x, $y, $z;
  40.     float  $rx, $ry, $rz;
  41.  
  42.  
  43.     // For each object in the selection list, check to see if
  44.     // and rigid bodies are present.
  45.     //
  46.     for ($i = 0; $i < size( $selObj ); $i++)
  47.     {
  48.         // Get a list of selected items and thier children.
  49.         //
  50.         string $kids[] = `ls -dag -leaf -showType $selObj[$i]`;
  51.  
  52.         // Check to see if we have any rigid bodies.
  53.         //
  54.         for ($j = 0; $j < size( $kids ); $j += 2)
  55.         {
  56.             // If a rigid body is found process it.
  57.             //
  58.             if ($kids[$j+1] == "rigidBody")
  59.             {
  60.                 // Indicate that a rigid body has been found.
  61.                 //
  62.                 $isRigid = 1;
  63.  
  64.                 string $parentList[] = `listRelatives -p $kids[$j]`;
  65.  
  66.                 $parentName = $parentList[0];
  67.  
  68.                 // Store the translate and rotate of the rigid body.
  69.                 // We need to set this value back if we change the rigid body to
  70.                 // active.
  71.                 //
  72.                 string $getAttrString = $parentName + ".translate";
  73.                 float $xyz[]    = `getAttr $getAttrString`;
  74.                 $getAttrString  = $parentName + ".rotate";
  75.                 float $rotate[] = `getAttr $getAttrString`;
  76.  
  77.                 // If we are setting a passive keyframe then we want to set the
  78.                 // attribute before we keyframe the position and rotation.  You
  79.                 // cannot set a keyframe if the rigid body is active.
  80.                 //
  81.                 string  $acitveString = $kids[$j] + ".active";
  82.                 setAttr $acitveString 0;
  83.                 
  84.                 // Set the keyframe for the group.
  85.                 //
  86.                 setKeyframe -at translateX -itt linear -ott linear -v $xyz[0]    $parentName;
  87.                 setKeyframe -at translateY -itt linear -ott linear -v $xyz[1]    $parentName;
  88.                 setKeyframe -at translateZ -itt linear -ott linear -v $xyz[2]    $parentName;
  89.                 setKeyframe -at rotateX    -itt linear -ott linear -v $rotate[0] $parentName;
  90.                 setKeyframe -at rotateY    -itt linear -ott linear -v $rotate[1] $parentName;
  91.                 setKeyframe -at rotateZ    -itt linear -ott linear -v $rotate[2] $parentName;
  92.                 
  93.                 // Set the active/passive keyframe.  We want to set the keyframe
  94.                 // for the active attribute after we set the translate/rotate 
  95.                 // keyframe.  You cannot set a keyframe if the rigid body is
  96.                 // active.
  97.                 //
  98.                 if ( $type == 1 )
  99.                 {
  100.                     setAttr $acitveString 1;
  101.  
  102.                     // Get the solver for this rigid body.
  103.                     //
  104.                     string $solverName  = `rigidBody -q -solver $kids[$j]`;
  105.                     string $getSolverID = $kids[$j] + ".solverId";
  106.                     int    $solverID    = `getAttr $getSolverID`;
  107.  
  108.                     // Make sure the active rigid body is set to the correct
  109.                     // position and rotation.  We need to set this in the solver
  110.                     // else the rigid body will get a new initial state.
  111.                     //
  112.                     string  $setAttrString = $solverName + ".translate[" + $solverID + "]";
  113.                     setAttr $setAttrString $xyz[0] $xyz[1] $xyz[2];
  114.                     $setAttrString = $solverName + ".rotate[" + $solverID + "]";
  115.                     setAttr $setAttrString $rotate[0] $rotate[1] $rotate[2] ;
  116.                 }
  117.  
  118.                 setKeyframe -attribute active -ott step -v $type $kids[$j];
  119.                 
  120.                 break;
  121.             }
  122.         }
  123.     }
  124.  
  125.     // If no rigid bodies are found then create rigid bodies
  126.     // out of the selected shapes and call this proc again.
  127.     //
  128.     if ($isRigid == 0)
  129.     {
  130.         int $created;
  131.  
  132.         $created = makeRigidActive( $type );
  133.  
  134.         if ( $created == 1 )
  135.         {
  136.             setRigidKeyframe( $type );
  137.         }
  138.     }
  139. }
  140.  
  141.  
  142.